﻿using System;
using System.Data;
using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
using System.Web;
using System.Web.Caching;


using LMD.Constant;
using LMD.Lib.Oracle;

namespace Cached
{
    /// <summary>
    /// Summary description for FeedGenerator
    /// </summary>
    public class FeedGenerator : CacheAbstraction
    {
        public DataTable GetFeedGeneratorList()
        {
            return GetFeedGeneratorList(false);
        }
        public DataTable GetFeedGeneratorList(bool bForceRefresh)
        {
            String sxCacheKey = KCache.FEED_GENERATOR;

            if(bForceRefresh)
            {
                HttpRuntime.Cache.Remove(sxCacheKey);
            }

            if (HttpRuntime.Cache[sxCacheKey] == null)
            {
                DBLib dbl = new DBLib();

                String sxQuery =
                    @"
                    select
                        gen.FEED_GENERATOR_ID ID,
                        gen.SQL,
                        gen.DESCRIPTION,
                        gen.CONNECTION,
                        gen.MINUTE_INTERVAL,
                        case when nvl(gen.VALID_TO, SysDate+1) > SysDate
                            then 'Y'
                        else 'N'
                        end VALIDITY,
                        src.NAME,
                        src.URL
                    from 
                        FEED_GENERATOR gen
                        left join FEED_SOURCE src                    
                            on gen.FEED_SOURCE_ID = src.FEED_SOURCE_ID 
                    order by
                        gen.FEED_SOURCE_ID ASC,
                        gen.FEED_GENERATOR_ID ASC
                    ";

                DataTable dt = dbl.GetDataTable(sxQuery);

                AddToCache(sxCacheKey, dt, CacheType.Daily);
                
            }
            return (DataTable)HttpRuntime.Cache[sxCacheKey];
        }        

        public override String GetCacheFilename()
        {
            return KCache.Filename.FEED_GENERATOR;
        }
    }
}